/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dotexe.webframework.core.bindings;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dotexe.webframework.core.collectionsource.CollectionSource;
/**
 *
 * @author jovan.tomasevic
 */
public class BindingCollectionSource extends BindingSource {

    public BindingCollectionSource() throws JSONException {
        super();
        this.put("Multiselect", false);
        this.put("SelectedValues", new JSONArray());
        this.put("SelectedValue", JSONObject.NULL);
        this.put("Source", new CollectionSource());
        this.put("Clear", false);
    }

    @Override
    public CollectionSource getSource() throws JSONException {
        return (CollectionSource) this.get("Source");
    }

    /**
     * Gets or sets the name.
     */
    public Integer getSelectedValue() throws JSONException {
        return this.getInt("SelectedValue");
    }

    public void setSelectedValue(Integer index) throws JSONException {
        if (index == null) {
            this.put("SelectedValue", JSONObject.NULL);
        } else {
            this.put("SelectedValue", index);
        }
    }

    public void setSelectedValues(ArrayList<Integer> indexes) throws JSONException {
        JSONArray array = new JSONArray(indexes);
        this.put("SelectedValues", array);
    }
}
